package com.star.truffle.shop.service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.star.truffle.shop.dao.ShopDao;
import com.star.truffle.shop.domain.Shop;
import com.star.truffle.shop.dto.req.ShopSaveReqeustDto;
import com.star.truffle.shop.dto.res.ShopListResponseDto;

@Service
public class ShopService {
  @Autowired
  private ShopDao shopDao;
  
  public Long addShop(Long hnUserId, ShopSaveReqeustDto saveDto) {
    Shop shop = Shop.builder()
        .shopId(1018701L)
        .hnUserId(hnUserId)
        .shopName(saveDto.getShopName())
        .build();
    shopDao.saveShop(shop);
    return shop.getShopId();
  }

  public List<ShopListResponseDto> listShop() {
    return shopDao.listShop(Map.of()).stream().map(s -> {
      ShopListResponseDto dto = new ShopListResponseDto();
      BeanUtils.copyProperties(s, dto);
      return dto;
    }).collect(Collectors.toList());
  }

}
